home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CRIBBAGE.PAK / CRIBBAGE.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  120 lines

  1. //--------------------------------------------------------------------------
  2. // Turbo Cribbage -- Copyright (c) 1995, Borland International
  3. //--------------------------------------------------------------------------
  4. #ifndef CRIBBAGE_H
  5. #define CRIBBAGE_H
  6.  
  7. #include <owl/window.h>
  8. #include "carddisp.h"
  9. #include "board.h"
  10. #include "dialogs.h"
  11.  
  12. const int DETAIL_MAXCOUNT = 20;
  13. const int DETAIL_MAXLEN = 128;
  14.  
  15. //
  16. // TGameWindow -- This class defines all the logic which controls the
  17. // game.
  18. //
  19. class TGameWindow : public TWindow {
  20.   public:
  21.     enum TGameState {
  22.       gsNewGame,       // waiting for new game command
  23.  
  24.       gsDeal,          // waiting for user to press the deal button
  25.  
  26.       gsDiscard,       // waiting for user to discard 2 cards
  27.  
  28.       gsCutAfterDeal,  // waiting for user to cut the deck, to show the fifth
  29.                        // card
  30.  
  31.       gsPegging,       // waiting for user to play a card, or
  32.                        // click the 'go' button
  33.  
  34.       gsPeggingFinish, // same as gsPegging, but the computer
  35.                        // is out of cards
  36.  
  37.       gsPeggingGo,     // computer has said 'go' to player,
  38.                        // waiting for player to hit 31
  39.  
  40.       gsGameOver       // somebody reached 121 points and won
  41.     };
  42.  
  43.     TGameWindow();
  44.    ~TGameWindow();
  45.  
  46.     void SetupWindow();
  47.  
  48.     BOOL GameOver();
  49.     int  FaceValue(int rank) {
  50.       return (rank>10) ? 10 : rank;   // return the vace value of the card
  51.     }
  52.     int  RunSize(int *ranks, int count);
  53.     int  ComputeHandPoints(TCardGroup* cards, TCard* extraCard, BOOL crib);
  54.     int  ComputePegPoints(int cardPlayer, BOOL goInEffect);
  55.     void ResetPegCardDisplay();
  56.     void ReclaimPegCards();
  57.     void PegCard(TCard* card, int player);
  58.     void ScoreComputerPegPoints();
  59.     BOOL ComputerPlayPegCard(BOOL goInEffect);
  60.     void TurnOverPegCards();
  61.     int  PlayableCards(TCardGroup* cards, BOOL *playable = 0);
  62.     void SetState(TGameState newState);
  63.     void Deal(BOOL prompt);
  64.     void ShowPoints();
  65.     void NewGame();
  66.     void DealButton();
  67.     void FixDeck();
  68.     void SaveGame() {}
  69.     void Exit() {
  70.       CloseWindow();
  71.     }
  72.     void SaveGameEnabler(TCommandEnabler& tce) {
  73.       tce.Enable(state!=gsNewGame);
  74.     }
  75.     void AboutBox() {
  76.       TDialog(this, ABOUT_DIALOG).Execute();
  77.     }
  78.     void LoadGame() {}
  79.     void Paint(TDC& dc, bool erase, TRect& rect);
  80.  
  81.     LRESULT CardSelected(WPARAM wparam, LPARAM lparam);
  82.  
  83.     int  PegCardsSum();
  84.     bool CanClose();
  85.     void GoButton();
  86.     void DoneButton();
  87.     void ComputerDiscard(int dealer);
  88.     void ComputerPlayCard(BOOL go = false);
  89.     void CountPoints(TCardGroup* cards);
  90.  
  91.     static TPoint handCardPos[6],cribCardPos[4],pegCardPos[8],topCardPos[1];
  92.  
  93.     TCardDisplay   *player[2],           // the two hands
  94.                    *crib,                // the crib
  95.                    *pegCards,            // where the cards are played
  96.                    *topCard;             // top card on the deck
  97.  
  98.     TCribbageBoard *board;               // the score board
  99.  
  100.     TButton        *deal, *go, *done;    // buttons used during game play
  101.  
  102.     TStatic        *instructions;        // a window to display help in
  103.  
  104.     TGameState   state;                  // current state of the game
  105.     uint         dealer;                 // who dealt the current hand
  106.  
  107.     TDeck    deck;                       // 52 cards
  108.     int      currentCribPos;
  109.     int      cardBackStyle;
  110.     int      pegCardOwner[8];            // keeps track of who owns each card
  111.                                          // that is played during pegging
  112.  
  113.     char *detail[DETAIL_MAXCOUNT];  // used for displaying individual point counts
  114.     int  detailCount;
  115.  
  116.   DECLARE_RESPONSE_TABLE(TGameWindow);
  117. };
  118.  
  119. #endif // CRIBBAGE_H
  120.